//
//  NearbyDetailViewController.m
//  HappyTrip
//
//  Created by GeminyXC on 15-3-23.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "NearbyDetailViewController.h"
#import "UIImageView+WebCache.h"

#import "NearbyPicObject.h"

#import "NearbyPicCollectionViewCell.h"

//星星类
#import "StarsView.h"

//图集页面
#import "NearAlbumViewController.h"
//照片放大页面
#import "NearbyPhotoViewController.h"

#import "DesDataObj.h"

#import "HappyDatabase.h"


@interface NearbyDetailViewController ()<UICollectionViewDataSource, UICollectionViewDelegate, UIScrollViewDelegate>

@property (nonatomic, retain)UILabel *titleNameLabel;//显示title
@property (nonatomic, retain)UIImageView *titleImageView;//标题图片
@property (nonatomic, retain)UILabel *starLabel;//推荐指数
@property (nonatomic, retain)UICollectionView *imageCollectionView;//图片展示区
@property (nonatomic, retain)UILabel *infoLabel;



@property (nonatomic, retain)UIScrollView *theScrollView;


@property (nonatomic, retain)UILabel *label1;//description
@property (nonatomic, retain)UILabel *label2;//address
@property (nonatomic, retain)UILabel *label3;//arrival_type
@property (nonatomic, retain)UILabel *label4;//opening_time
@property (nonatomic, retain)UILabel *label5;//tel
@property (nonatomic, retain)UILabel *label6;//website
@property (nonatomic, assign)CGFloat heightAll;//存储label1到label6的总高度

//图片处理相关
@property (nonatomic, retain)NSMutableArray *arrPic;
@property (nonatomic, retain)NSMutableArray *arrPics;
@property (nonatomic, retain)UIButton *picButton;

//数据库相关

@property (nonatomic, retain)HappyObject *happyObject;

//收藏提示
@property (nonatomic, retain)UIAlertView *stowAlertView;

@end

@implementation NearbyDetailViewController

- (void)dealloc
{
    [_titleNameLabel release];
    [_titleImageView release];
    [_starLabel release];
    [_imageCollectionView release];
    [_infoLabel release];
    [_theScrollView release];
    [_label1 release];
    [_label2 release];
    [_label3 release];
    [_label4 release];
    [_label5 release];
    [_label6 release];
    [_arrPic release];
    [_arrPics release];
    [_picButton release];
    [_happyObject release];
    [_type release];
    [_urlID release];
    [_stowAlertView release];
    [_nearbyDetailInfo release];
    [super dealloc];
}

- (void)handleData
{
//    NSString *urlStr = @"http://api.breadtrip.com/destination/place/5/2387459549/";
    NSString *urlStr = [NSString stringWithFormat:@"http://api.breadtrip.com/destination/place/%@/%@/", self.type, self.urlID];
    NSLog(@"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!%@", urlStr);
    NSLog(@"%@", urlStr);
    //此数据最外层是一个字典,所需要的值也在这个字典当中
    
    //没有缓存,想办法在断网的时候可以显示缓存的内容
    NSString *docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
    NSString *path = [NSString stringWithFormat:@"%@/%ld.aa", docPath, [urlStr hash]];
    
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:urlStr parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        BOOL result = [NSKeyedArchiver archiveRootObject:responseObject toFile:path];
        NSLog(@"%d", result);
  
        self.nearbyDetailInfo = [[NearbyDetailObject alloc] initWithNSDictionary:responseObject];
        
        [self giveValueMethod];
 
        
        [self theAction];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"发生未知错误");
        
        id result = [NSKeyedUnarchiver unarchiveObjectWithFile:path];
        NSLog(@"这个是什么呢%@", result);
        
        self.nearbyDetailInfo = [[NearbyDetailObject alloc] initWithNSDictionary:result];

        [self giveValueMethod];
        
        [self theAction];
    }];
    

    
}

- (void)giveValueMethod
{

    
    self.titleNameLabel.text = self.nearbyDetailInfo.name;
    [self labelAll];

    //获取详细信息界面的图片
    NSArray *arr1 = self.nearbyDetailInfo.hottest_places;
    NSDictionary *dic1 = arr1[0];
    NSString *imageStr = [dic1 objectForKey:@"photo"];//该字符串不需要转码?
    NSURL *imageUrl = [NSURL URLWithString:imageStr];
    [self.titleImageView setImageWithURL:imageUrl placeholderImage:[UIImage imageNamed:@"picLoading.png"]];
    
    //数据库相关(数据处理相关写在此处,可以在数据处理完毕后,再执行相关方法)
//    NeaDataBase *db = [NeaDataBase shareInstance];
//    NSMutableArray *arrDB = [db selectAll];
//    NSMutableArray *arrDBOK = [NSMutableArray array];
//    for (NSInteger i = 0; i < arrDB.count; i++) {
//        NSString *str = [[arrDB objectAtIndex:i] valueForKey:@"name"];
//        [arrDBOK addObject:str];
//    }
//    if ([arrDBOK containsObject:self.titleNameLabel.text]) {
//        [self.navigationItem.rightBarButtonItem setImage:[UIImage imageNamed:@"star1.png"]];
//    }else{
//        [self.navigationItem.rightBarButtonItem setImage:[UIImage imageNamed:@"star3.png"]];
//    }



}

//处理图片接口
- (void)picHandleDataOK
{
    for (NSDictionary *picDic in self.arrPic) {
        NearbyPicObject *nearbyPicInfo = [[NearbyPicObject alloc] initWithNSDictionary:picDic];
        [self.arrPics addObject:nearbyPicInfo];
        [nearbyPicInfo release];
    }
//    NSLog(@"太多注释都看不出来了%@", self.arrPics);
//    NSLog(@"-=-=-=-=  %ld", self.arrPics.count);
    [_imageCollectionView reloadData];
}

- (void)picHandleData
{
    NSString *picStrUrl = [NSString stringWithFormat:@"http://api.breadtrip.com/destination/place/%@/%@/photos/?start=0&count=100&gallery_mode=true", self.type, self.urlID];//图片原来显示为21张,被改为100
    //处理缓存
    NSString *picPocPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
    NSString *picPath = [NSString stringWithFormat:@"%@/%ld.aa", picPocPath, [picStrUrl hash]];
    AFHTTPRequestOperationManager *picManager = [AFHTTPRequestOperationManager manager];
    [picManager GET:picStrUrl parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        BOOL result = [NSKeyedArchiver archiveRootObject:responseObject toFile:picPath];//存入缓存
        NSLog(@"%d", result);
//        self.arrPic = [NSMutableArray array];//不用初始化,只给一个指针即可
        self.arrPic = [responseObject objectForKey:@"items"];
        [self picHandleDataOK];
        [self.picButton addTarget:self action:@selector(picButtonAction:) forControlEvents:UIControlEventTouchUpInside];//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        id result = [NSKeyedUnarchiver unarchiveObjectWithFile:picPath];//从缓存中取出
        self.arrPic = [result objectForKey:@"items"];
        [self picHandleDataOK];
    }];
}

- (void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBar.barTintColor = [UIColor whiteColor];
    self.tabBarController.tabBar.hidden = NO;
    
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0 / 255.0 green:170.0 / 255.0 blue:205.0 / 255.0 alpha:1.0];
    self.tabBarController.tabBar.hidden = NO;
//    self.view.backgroundColor = [UIColor colorWithRed:250.0 / 255.0 green:240.0 / 255.0 blue:220.0 / 255.0 alpha:1.0];
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName, nil]];
    
#pragma mark happy数据库相关
    HappyDatabase *happyDb = [HappyDatabase shareInstance];
    NSMutableArray *arrDB = [happyDb selectAll];
    NSMutableArray *arrDBOK = [NSMutableArray array];
    for (NSInteger i = 0; i < arrDB.count; i++) {
        NSString *str = [[arrDB objectAtIndex:i] valueForKey:@"theUrlId"];
        [arrDBOK addObject:str];
    }
    if ([arrDBOK containsObject:self.urlID]) {
        [self.navigationItem.rightBarButtonItem setImage:[UIImage imageNamed:@"yishoucang.png"]];
    }else{
        [self.navigationItem.rightBarButtonItem setImage:[UIImage imageNamed:@"weishoucang.png"]];
    }

    //将数据处理写在视图将要出现的地方
  self.arrPics = [NSMutableArray array];
    [self picHandleData];
    [self handleData];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    //happy数据库相关
    HappyDatabase *happyDb = [HappyDatabase shareInstance];
    [happyDb openDB];
    [happyDb createTable];

    self.view.backgroundColor = [UIColor colorFromHexCode:@"#F5FFFA"];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"iconfont-fanhui.png"] style:UIBarButtonItemStylePlain target:self action:@selector(leftBarButtonItemAction:)];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];
    

    
    //收藏按钮
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] init];
    [self.navigationItem.rightBarButtonItem setStyle:UIBarButtonItemStylePlain];
    [self.navigationItem.rightBarButtonItem setTarget:self];
    [self.navigationItem.rightBarButtonItem setAction:@selector(barButtonAction:)];
    self.navigationItem.rightBarButtonItem.tintColor = [UIColor whiteColor];
    
    
    
    self.theScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, VIEW_WIDTH + 30, VIEW_HEIGHT)];
//    _theScrollView.contentSize = CGSizeMake(0, 900);//加载完数据后再确定其尺寸
    self.theScrollView.backgroundColor = [UIColor clearColor];
    _theScrollView.bounces = YES;//弹动效果
    self.theScrollView.showsHorizontalScrollIndicator = NO;
    self.theScrollView.showsVerticalScrollIndicator = NO;
    self.theScrollView.delegate = self;
    [self.view addSubview:_theScrollView];
    [self.theScrollView release];
    
    

    UILabel *loadLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, (VIEW_HEIGHT) * 3 / 16, VIEW_WIDTH, 50)];
    loadLabel.text = @"图片加载中...";
    loadLabel.textColor = [UIColor whiteColor];
    loadLabel.textAlignment = NSTextAlignmentCenter;
    [self.theScrollView addSubview:loadLabel];
    [loadLabel release];
    
    self.titleImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, VIEW_WIDTH, (VIEW_HEIGHT) * 3 / 8)];
//    self.titleImageView.backgroundColor = [UIColor yellowColor];
    //两者结合使图片剪切并适应imageView的大小
    self.titleImageView.contentMode = UIViewContentModeScaleAspectFill;
    self.titleImageView.clipsToBounds = YES;
    [self.theScrollView addSubview:_titleImageView];
    [_titleImageView release];
    
    self.titleNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, (VIEW_HEIGHT) * 3 / 8 , VIEW_WIDTH, (VIEW_HEIGHT) / 8)];
//    self.titleNameLabel.backgroundColor = [UIColor cyanColor];
    self.titleNameLabel.font = [UIFont systemFontOfSize:30];
    self.titleNameLabel.textColor = [UIColor blackColor];
    self.titleNameLabel.textAlignment = NSTextAlignmentCenter;
    NSLog(@"标题信息:%@", self.titleNameLabel.text);
    [self.theScrollView  addSubview:_titleNameLabel];
    [_titleNameLabel release];
    
    self.starLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, (VIEW_HEIGHT) / 2 , VIEW_WIDTH / 3, (VIEW_HEIGHT) / 16)];
    self.starLabel.text = @"推荐指数:";
    self.starLabel.backgroundColor = [UIColor clearColor];
    self.starLabel.textAlignment = NSTextAlignmentRight;
    self.starLabel.textColor = [UIColor blackColor];
    [self.theScrollView addSubview:_starLabel];
    [_starLabel release];
    
    //星星推荐指数
    NSInteger starNumber = arc4random() % (60 - 0 + 1) + 0;
    StarsView *starView = [[StarsView alloc] initWithFrame:CGRectMake(VIEW_WIDTH / 3, (VIEW_HEIGHT) / 2 + (VIEW_HEIGHT) / 75 , (VIEW_HEIGHT) * 5 / 30, (VIEW_HEIGHT) / 30)];
    [starView getWithStars:[NSString stringWithFormat:@"%lu", starNumber]];
    //    starView.backgroundColor = [UIColor blackColor];
    [self.theScrollView addSubview:starView];
    [starView release];
    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.itemSize = CGSizeMake((VIEW_HEIGHT) * 3 / 16, (VIEW_HEIGHT) * 3 / 16);
//    flowLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);//边界范围
    flowLayout.minimumLineSpacing = 3;//最小行间距,由于此处设置为水平滚动,所以可理解为列间距
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;//设置其水平滚动
    self.imageCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, (VIEW_HEIGHT) * 9 / 16, VIEW_WIDTH, (VIEW_HEIGHT) * 3 / 16) collectionViewLayout:flowLayout];
//    self.imageCollectionView.pagingEnabled = YES;//按页翻貌似要设置偏移量
    self.imageCollectionView.dataSource = self;
    self.imageCollectionView.delegate = self;
    self.imageCollectionView.backgroundColor = [UIColor clearColor];
    [self.theScrollView addSubview:_imageCollectionView];
    [flowLayout release];
    [_imageCollectionView release];
    
    //点击显示更多图片Button
    self.picButton = [UIButton buttonWithType:UIButtonTypeSystem];
    self.picButton.frame = CGRectMake(VIEW_WIDTH * 5 / 6, (VIEW_HEIGHT) / 2, VIEW_WIDTH  / 6, (VIEW_HEIGHT) / 16);
    [self.picButton setTitle:@">>" forState:UIControlStateNormal];
    self.picButton.titleLabel.font = [UIFont systemFontOfSize:20];
    self.picButton.backgroundColor = [UIColor clearColor];
    [self.picButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
//    [self.picButton addTarget:self action:@selector(picButtonAction:) forControlEvents:UIControlEventTouchUpInside];//这个按钮Action要写到图片请求下来后,否则图片还未处理完,进入图集就为空
    [self.theScrollView addSubview:_picButton];
    
    

    self.infoLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, (VIEW_HEIGHT) * 12 / 16, VIEW_WIDTH, (VIEW_HEIGHT) * 2 / 16)];
    self.infoLabel.text = @"基本信息";
    self.infoLabel.font = [UIFont systemFontOfSize:25];
    self.infoLabel.textColor = [UIColor blackColor];
    self.infoLabel.textAlignment = NSTextAlignmentCenter;
    [self.theScrollView addSubview:_infoLabel];
    [_infoLabel release];

    
    
//   为imageCollectionView的cell注册
    [self.imageCollectionView registerClass:[NearbyPicCollectionViewCell class] forCellWithReuseIdentifier:@"reuse"];
    



    
}

- (void)barButtonAction:(UIBarButtonItem *)button
{

#pragma mark happy数据库相关
    HappyDatabase *happyDB = [HappyDatabase shareInstance];
    self.happyObject = [[HappyObject alloc] init];
    _happyObject.theType = self.type;
    _happyObject.theUrlId = self.urlID;
    _happyObject.theName = self.titleNameLabel.text;
    
    self.stowAlertView = [[UIAlertView alloc] initWithTitle:nil message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
    
    
    if ([self.navigationItem.rightBarButtonItem.image isEqual:[UIImage imageNamed:@"weishoucang.png"]]) {
        [self.navigationItem.rightBarButtonItem setImage:[UIImage imageNamed:@"yishoucang.png"]];
        [happyDB insertHappyObject:_happyObject];
        [_stowAlertView show];
        [_stowAlertView setTitle:@"已成功收藏"];
    }else{
        [self.navigationItem.rightBarButtonItem setImage:[UIImage imageNamed:@"weishoucang.png"]];
        [happyDB deleteHappyObject:_happyObject];
        [_stowAlertView show];
        [_stowAlertView setTitle:@"已取消收藏"];
    }
    [_happyObject release];
    [_stowAlertView release];
    
    [NSTimer scheduledTimerWithTimeInterval:0.5f
                                     target:self
                                   selector:@selector(dismissAlertView:)
                                   userInfo:nil
                                    repeats:NO];

}

- (void)dismissAlertView:(NSTimer*)timer {
    NSLog(@"Dismiss alert view");
    [self.stowAlertView dismissWithClickedButtonIndex:0 animated:YES];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    if (self.arrPics.count > 6) {
        return 6;
    } else {
    
        return self.arrPics.count;
    }
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    NearbyPicCollectionViewCell *cell = [self.imageCollectionView dequeueReusableCellWithReuseIdentifier:@"reuse" forIndexPath:indexPath];
    cell.contentView.backgroundColor = [UIColor blackColor];
    
   NearbyPicObject *nearbyPicInfo = [self.arrPics objectAtIndex:indexPath.row];

    cell.nearbyPicInfo = nearbyPicInfo;
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"选中当前cell");
    NearbyPhotoViewController *photoVC = [[NearbyPhotoViewController alloc] init];
    photoVC.arrPhoto = self.arrPics;
    photoVC.itemOK = indexPath.item;
    [self.navigationController pushViewController:photoVC animated:YES];
    [photoVC release];
}

- (void)picButtonAction:(UIButton *)button
{
    NSLog(@"进入图集");
    NearAlbumViewController *albumVC = [[NearAlbumViewController alloc] init];
    albumVC.arrAlbum = self.arrPics;
    [self.navigationController pushViewController:albumVC animated:YES];
    [albumVC release];
}

//下拉图片放大
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    NSLog(@"能动么");
    CGFloat offset_y = self.theScrollView.contentOffset.y;
    if (offset_y < 0) {
        CGFloat factor = ((ABS(offset_y)+(VIEW_HEIGHT + 64 + 49) / 3)*VIEW_WIDTH)/((VIEW_HEIGHT + 64 + 49) / 3);
        CGRect f = CGRectMake(-(factor-VIEW_WIDTH)/2, 0, factor, (VIEW_HEIGHT + 64 + 49) / 3 +ABS(offset_y));
        self.titleImageView.frame = f;
        self.titleImageView.center = CGPointMake(_titleImageView.center.x, _titleImageView.center.y - ABS(offset_y));
    }
    
}

- (void)theAction
{
    NSLog(@"BBBBBBBBBBBB%f", self.heightAll);
    _theScrollView.contentSize = CGSizeMake(0, self.heightAll + 35);
}

- (void)labelAll
{
        // ---------------------------------------
    UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, (VIEW_HEIGHT + 64 + 49) * 14 / 16, VIEW_WIDTH, 20)];
    imageView1.image = [UIImage imageNamed:@"description1.png"];
    imageView1.contentMode = UIViewContentModeScaleAspectFit;
    imageView1.clipsToBounds = YES;
    [self.theScrollView addSubview:imageView1];
    [imageView1 release];
    
        self.label1 = [[UILabel alloc] initWithFrame:CGRectMake(5, imageView1.frame.origin.y + imageView1.frame.size.height, VIEW_WIDTH - 35, 100)];
//        self.label1.backgroundColor = [UIColor greenColor];
        if (self.nearbyDetailInfo.descriptionOK.length != 0) {
        self.label1.text = [NSString stringWithFormat:@"概览:   %@", self.nearbyDetailInfo.descriptionOK];
        }else{
        self.label1.text = @"概览:    暂无信息";
        }
        self.label1.textColor = [UIColor blackColor];
        self.label1.font = [UIFont systemFontOfSize:13.5];
        self.label1.numberOfLines = 0;
        [self.label1 sizeToFit];
        [self.theScrollView addSubview:_label1];
        [_label1 release];
    

    


    //            -------------------------------
    UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:CGRectMake(0, imageView1.frame.origin.y + 20 + self.label1.frame.size.height, VIEW_WIDTH, 20)];
    
    imageView2.image = [UIImage imageNamed:@"address2.png"];
    imageView2.contentMode = UIViewContentModeScaleAspectFit;
    imageView2.clipsToBounds = YES;
    [self.theScrollView addSubview:imageView2];
    [imageView2 release];
    
        self.label2 = [[UILabel alloc] initWithFrame:CGRectMake(5, imageView2.frame.origin.y + 20, VIEW_WIDTH - 35, 100)];
//        self.label2.backgroundColor = [UIColor purpleColor];
            if (self.nearbyDetailInfo.address.length != 0) {
        self.label2.text = [NSString stringWithFormat:@"地址:   %@", self.nearbyDetailInfo.address];
            }else{
        self.label2.text = @"地址:   地址无法确定";
            }
    self.label2.textColor = [UIColor blackColor];
        self.label2.font = [UIFont systemFontOfSize:13.5];
        self.label2.numberOfLines = 0;
        [self.label2 sizeToFit];
        [self.theScrollView addSubview:_label2];
        [_label2 release];
        
 
//        NSLog(@"label2的高度:%f", _label2.frame.size.height);//
    
    
    
    
    //            -------------------------------
    UIImageView *imageView3 = [[UIImageView alloc] initWithFrame:CGRectMake(0, imageView2.frame.origin.y + 20 + self.label2.frame.size.height, VIEW_WIDTH, 20)];
    imageView3.image = [UIImage imageNamed:@"arrival_type3.png"];
    imageView3.contentMode = UIViewContentModeScaleAspectFit;
    imageView3.clipsToBounds = YES;
    [self.theScrollView addSubview:imageView3];
    [imageView3 release];
    
    self.label3 = [[UILabel alloc] initWithFrame:CGRectMake(5, imageView3.frame.origin.y + 20, VIEW_WIDTH - 35, 100)];
//    self.label3.backgroundColor = [UIColor magentaColor];
    if (self.nearbyDetailInfo.arrival_type.length != 0) {
    self.label3.text = [NSString stringWithFormat:@"到达方式:   %@", self.nearbyDetailInfo.arrival_type];
    }else{
    self.label3.text = @"到达方式:   没有合适的到达方式";
    }
    self.label3.textColor = [UIColor blackColor];
    self.label3.font = [UIFont systemFontOfSize:13.5];
    self.label3.numberOfLines = 0;
    [self.label3 sizeToFit];
    [self.theScrollView addSubview:_label3];
    [_label3 release];
        

//        NSLog(@"label3的高度:%f", _label3.frame.size.height);
    
    
    //            -------------------------------
    UIImageView *imageView4 = [[UIImageView alloc] initWithFrame:CGRectMake(0, imageView3.frame.origin.y + 20 + self.label3.frame.size.height, VIEW_WIDTH, 20)];
    imageView4.image = [UIImage imageNamed:@"opening_time4.png"];
    imageView4.contentMode = UIViewContentModeScaleAspectFit;
    imageView4.clipsToBounds = YES;
    [self.theScrollView addSubview:imageView4];
    [imageView4 release];

    self.label4 = [[UILabel alloc] initWithFrame:CGRectMake(5, imageView4.frame.origin.y + 20, VIEW_WIDTH, 100)];
//    self.label4.backgroundColor = [UIColor yellowColor];
    if (self.nearbyDetailInfo.opening_time.length != 0) {
    self.label4.text = [NSString stringWithFormat:@"开放时间:   %@", self.nearbyDetailInfo.opening_time];
    }else{
    self.label4.text = @"开放时间:   全天";
    }
    self.label4.textColor = [UIColor blackColor];
    self.label4.font = [UIFont systemFontOfSize:13.5];
    self.label4.numberOfLines = 0;
    [self.label4 sizeToFit];
    [self.theScrollView addSubview:_label4];
    [_label4 release];
        

//        NSLog(@"label4的高度:%f", _label4.frame.size.height);
    
    
    //            -------------------------------
    UIImageView *imageView5 = [[UIImageView alloc] initWithFrame:CGRectMake(0, imageView4.frame.origin.y + 20 + self.label4.frame.size.height, VIEW_WIDTH, 20)];
    imageView5.image = [UIImage imageNamed:@"tel5.png"];
    imageView5.contentMode = UIViewContentModeScaleAspectFit;
    imageView5.clipsToBounds = YES;
    [self.theScrollView addSubview:imageView5];
    [imageView5 release];

    self.label5 = [[UILabel alloc] initWithFrame:CGRectMake(5, imageView5.frame.origin.y + 20, VIEW_WIDTH - 5, 100)];
//    self.label5.backgroundColor = [UIColor cyanColor];
    if (self.nearbyDetailInfo.tel.length != 0) {
    self.label5.text = [NSString stringWithFormat:@"联系方式:   %@" ,self.nearbyDetailInfo.tel];
    }else{
    self.label5.text = @"联系方式:    暂无信息";
    }
    self.label5.textColor = [UIColor blackColor];
    self.label5.font = [UIFont systemFontOfSize:13.5];
    self.label5.numberOfLines = 0;
    [self.label5 sizeToFit];
    [self.theScrollView addSubview:_label5];
    [_label5 release];
        

//        NSLog(@"label5的高度:%f", _label5.frame.size.height);
    
    //            -------------------------------
    UIImageView *imageView6 = [[UIImageView alloc] initWithFrame:CGRectMake(0, imageView5.frame.origin.y + 20 + self.label5.frame.size.height, VIEW_WIDTH, 20)];
    imageView6.image = [UIImage imageNamed:@"website6.png"];
    imageView6.contentMode = UIViewContentModeScaleAspectFit;
    imageView6.clipsToBounds = YES;
    [self.theScrollView addSubview:imageView6];
    [imageView6 release];
    
    self.label6 = [[UILabel alloc] initWithFrame:CGRectMake(5, imageView6.frame.origin.y + 20, VIEW_WIDTH - 35, 100)];
//    self.label6.backgroundColor = [UIColor blueColor];
    if (self.nearbyDetailInfo.website.length != 0) {
    self.label6.text = [NSString stringWithFormat:@"网址:   %@", self.nearbyDetailInfo.website];
    }else{
    self.label6.text = @"网址:   暂未提供网址";
    }
    self.label6.textColor = [UIColor blackColor];
    self.label6.font = [UIFont systemFontOfSize:13.5];
    self.label6.numberOfLines = 0;
    [self.label6 sizeToFit];
    [self.theScrollView addSubview:_label6];
    [_label6 release];
    //            -------------------------------
    self.heightAll = imageView6.frame.origin.y + 20 + self.label6.frame.size.height;
    NSLog(@"AAAAAAAAAAAAAAAAA%f", self.heightAll);
}

- (void)leftBarButtonItemAction:(UIBarButtonItem *)button
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
